package com.example.administrator.nl.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.nl.R;
import com.example.administrator.nl.bean.OrderStatistics;
import com.example.administrator.nl.util.DecimalFormatUtil;
import com.example.administrator.nl.util.RandomUtil;

import java.util.ArrayList;
import java.util.List;

public class Mian2Activity extends AppCompatActivity {
    TextView tv;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mian2);

        tv = findViewById(R.id.tv);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                demo();
            }
        });

    }

    int mAppOrder;
    int mXcxOrder;
    // 接单前关闭订单
    int mCloseFrontOrder;

    // 接单后关闭订单
    int mCloseAfterOrder;

    // 人工指派订单
    int mAssignOrder;

    // 再次预约订单
    int mMaleAppointment;


    private void demo() {
        // 随机出的订单
        int randomOrder = RandomUtil.randomInt(20, 10);
        Log.d("mian2_随机出的订单", randomOrder + "");

        // 接单前关闭订单
        mCloseFrontOrder = (int) (randomOrder * (DecimalFormatUtil.format2(RandomUtil.randomDouble(0.10, 0.15))));

        // 接单后关闭订单
        mCloseAfterOrder = (int) (randomOrder * (DecimalFormatUtil.format2(RandomUtil.randomDouble(0.10, 0.15))));

        // 人工指派订单
        mAssignOrder = (int) (randomOrder * (DecimalFormatUtil.format2(RandomUtil.randomDouble(0.20, 0.30))));

        // 再次预约订单
        mMaleAppointment = (int) (randomOrder * (DecimalFormatUtil.format2(RandomUtil.randomDouble(0.20, 0.30))));

        // app订单数量
        mAppOrder = randomOrder - (randomOrder - (int) (randomOrder * (DecimalFormatUtil.format2(RandomUtil.randomDouble(0.70, 0.80)))));
        // 小程序订单数量
        mXcxOrder = randomOrder - mAppOrder;

        // 有效订单
        int validOrder = randomOrder - mCloseFrontOrder - mCloseAfterOrder;


        int hzOrder = (int) (validOrder * DecimalFormatUtil.format2(RandomUtil.randomDouble(0.60, 0.70)));
        int sjzOrder = (int) ((validOrder - hzOrder) - ((validOrder - hzOrder) * DecimalFormatUtil.format2(RandomUtil.randomDouble(0.50, 0.60))));
        int bdOrder = validOrder - hzOrder - sjzOrder;

        // 杭州平台信息费
        double hzServiceCharge = 0;
        // 石家庄平台信息费
        double sjzServiceCharge = 0;
        // 保定平台信息费
        double bdServiceCharge = 0;

        // 杭州订单总金额
        int hzPrice = 0;

        // 石家庄订单总金额
        int sjzPrice = 0;

        // 保定平订单总金额
        int bdPrice = 0;

        //10分钟订单总金额
        double price = 0;

        // 杭州服务者收益
        double hzServerProfit = 0.0;
        // 杭州
        for (int i = 0; i < hzOrder; i++) {
            hzPrice += RandomUtil.randomInt(500, 150);
        }
        hzServiceCharge = DecimalFormatUtil.format2(hzPrice * 0.18);
        hzServerProfit = hzPrice - hzServiceCharge;

        // 石家庄服务者收益
        double sjzServerProfit = 0.0;
        // 石家庄
        for (int i = 0; i < sjzOrder; i++) {
            sjzPrice += RandomUtil.randomInt(500, 150);
        }
        sjzServiceCharge = DecimalFormatUtil.format2(sjzPrice * 0.08);
        sjzServerProfit = DecimalFormatUtil.format2(sjzPrice - sjzServiceCharge);

        // 保定服务者收益
        double bdServerProfit = 0.0;
        // 保定
        for (int i = 0; i < bdOrder; i++) {
            bdPrice += RandomUtil.randomInt(500, 150);
        }
        bdServiceCharge = DecimalFormatUtil.format2(bdPrice * 0.08);
        bdServerProfit = bdPrice - bdServiceCharge;

        price = hzPrice + sjzPrice + bdPrice;


        // 使用的优惠券
        int couponPrice = (int) (price * DecimalFormatUtil.format2(RandomUtil.randomDouble(0.03, 0.06)));

        // 支付金额
        double payPrice = price - couponPrice;

        // 服务定金
        int serviceDeposit = (int) (payPrice * DecimalFormatUtil.format2(RandomUtil.randomDouble(0.10, 0.20)));

        // 服务保证金
        int serviceMargin = (int) (payPrice * 0.20);

        //推广员分成
        double bd = DecimalFormatUtil.format2(price * DecimalFormatUtil.format2(RandomUtil.randomDouble(0.02, 0.06)));


        Log.d("mian2_接单前关闭订单", mCloseFrontOrder + "");
        Log.d("mian2_接单后关闭订单", mCloseAfterOrder + "");
        Log.d("mian2_人工指派订单", mAssignOrder + "");
        Log.d("mian2_再次预约订单", mMaleAppointment + "");
        Log.d("mian2_APP订单", mAppOrder + "");
        Log.d("mian2_小程序订单", mXcxOrder + "");
        Log.d("mian2_10分钟订单总金额", price + "");
        Log.d("mian2_使用的优惠券", couponPrice + "");
        Log.d("mian2_支付金额", payPrice + "");
        Log.d("mian2_服务定金", serviceDeposit + "");
        Log.d("mian2_服务保证金", serviceMargin + "");
        Log.d("mian2_有效订单", serviceMargin + "");
        Log.d("mian2_杭州订单", hzOrder + "");
        Log.d("mian2_石家庄订单", sjzOrder + "");
        Log.d("mian2_保定订单", bdOrder + "");
        Log.d("mian2_杭州平台信息费", hzServiceCharge + "");
        Log.d("mian2_石家庄平台信息费", sjzServiceCharge + "");
        Log.d("mian2_保定平台信息费", bdServiceCharge + "");
        Log.d("mian2_杭州订单总金额", hzPrice + "");
        Log.d("mian2_石家庄订单总金额", sjzPrice + "");
        Log.d("mian2_保定平订单总金额", bdPrice + "");
        Log.d("mian2_杭州服务者收益", hzServerProfit + "");
        Log.d("mian2_石家庄服务者收益", sjzServerProfit + "");
        Log.d("mian2_保定服务者收益", bdServerProfit + "");
        Log.d("mian2_所有订单总金额(包含优惠券)", price + "");
        Log.d("mian2_订单支付金额", payPrice + "");
        Log.d("mian2_优惠券", couponPrice + "");
        Log.d("mian2_服务定金", serviceDeposit + "");
        Log.d("mian2_服务保证金", serviceMargin + "");
        Log.d("mian2_推广员分成", bd + "");

    }


}
